class Node:
    flag = False
    map = {}

    def __init__(self, val):
        self.val = val

class Trie:
    root = Node('fake')

    def __init__(self):
        """
        Initialize your data structure here.
        """

    def insert(self, word):
        """
        Inserts a word into the trie.
        :type word: str
        :rtype: void
        """
        now = self.root
        for i in range(0, len(word)):
            #  遍历每个字符
            if not now.map.__contains__(word[i]):
                #  没有那就新增
                now.map[word[i]] = Node(word[i])
            now = now.map[word[i]]
            if i == len(word)-1:
                now.flag = True
                return

    def search(self, word):
        """
        Returns if the word is in the trie.
        :type word: str
        :rtype: bool
        """
        now = self.root
        for i in range(0, len(word)):
            if not now.map.__contains__(word[i]):
                return False
            now = now.map[word[i]]
        return now.flag

    def startsWith(self, prefix):
        """
        Returns if there is any word in the trie that starts with the given prefix.
        :type prefix: str
        :rtype: bool
        """
        now = self.root
        for i in range(0, len(prefix)):
            if not now.map.__contains__(prefix[i]):
                return False
            now = now.map[prefix[i]]
        return True

# Your Trie object will be instantiated and called as such:
# obj = Trie()
# obj.insert(word)
# param_2 = obj.search(word)
# param_3 = obj.startsWith(prefix)

tree =Trie()
print(tree.startsWith("a"))